<!--
 * @message: 文件导入组件
-->
<template>
  <div style="display: inline-block;">
  <Modal
  title="文件导入"
  v-model="isImport"
  >
  <div>{{desc}}</div>
    <div slot="footer">
      <Button type="primary" style="margin-right: 10px;" icon="md-arrow-down" @click="getExcelImportTemplate(templateName, dowmTempName)">下载模板</Button>
      <BaseUpload
        name="file"
        :multiple="true"
        :show-upload-list="false"
        :action="action"
        :btnIcon="icon"
        :btnText="text"
        @publicSuccess="publicSuccess"
      />
    </div>
  </Modal>
  <Button type="primary" style="margin-left: 10px;" @click="isImport = true">导入</Button>
  </div>
</template>

<script>
import { getExcelImportTemplate } from '../../api/modules/user/user.js'
import BaseUtil from '../../utils/BaseUtil'

export default {
  props: {
    /**
       * 请求地址
       */
    action: {
      type: String,
      default: ''
    },
    /**
       * 描述
       */
    desc: {
      type: String,
      default: '快速批量添加信息,如没有下载导入模板,请先下载导入模板'
    },
    /**
     * 下载模板名
     *
     */
    templateName: {
      type: String,
      default: ''
    },
    /**
     * 下载文件名
     */
    dowmTempName: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      icon: 'md-add',
      text: '导入',
      isImport: false
    }
  },
  methods: {
    /**
       * 下载模板
       */
    getExcelImportTemplate (templateName, dowmTempName) {
      getExcelImportTemplate(templateName).then(res => {
        BaseUtil.downFile(res.data, dowmTempName)
      })
    },
    /**
       * 导入用户信息
       */
    publicSuccess (params) {
      this.$emit('onSuccess', params)
    }
  },
  components: {
    BaseUpload: () => import('./BaseUpload')
  }
}
</script>

<style>
</style>
